﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for User
/// </summary>
public class OfficeOnlineUser
{

    public enum UserTypeEnum
    {
        Associate = 1, Manager = 2, Administrator = 3
    }

    private static string[] userTypes = { "Associate", "Manager", "Administrator" };

    private string userName;
    private int userType;
    private string userRealName;
    private string userEmailAddress;

    public OfficeOnlineUser(string userName)
    {
        this.userName = userName;        
    }

    public OfficeOnlineUser(string userName, int userType, string userRealName,string userEmailAddress)
	{
        this.userName = userName;
        this.userType = userType;
        this.userRealName = userRealName;
        this.userEmailAddress = userEmailAddress;        
	}
    
    public string UserName
    {
        get
        {
            return userName;
        }
    }

    public int UserType
    {
        get
        {
            return userType;
        }
    }

    public string UserRealName
    {
        get
        {
            return userRealName;
        }
    }

    public string UserEmailAddress
    {
        get
        {
            return userEmailAddress;
        }
    }

    public static string[] UserTypes
    {
        get
        {
            return userTypes;
        }
    }
    
    public DataTable GetCurrentChatRooms()
    {
        string command = "sp_tb_user_GetCurrentChatRooms @userID='" + this.userName + "'";
        SqlConnection sqlCon = new SqlConnection(DatabaseFunctions.GetConnectionString());
        sqlCon.Open();
        SqlDataAdapter sda = new SqlDataAdapter(command, sqlCon);
        DataTable dsReminders = new DataTable();
        sda.Fill(dsReminders);

        string command2 = "";
        SqlDataAdapter sda2;
        DataTable dsReminders2;
        int idx = 0;
        foreach (DataRow row in dsReminders.Rows)
        {
            //this is a temporary fix to roomName bug 
            //roomName, in PM, is dynamic. it should always be the name of the other user the current user is talking to.
            //storing a roomname in the database would only work if the chatroom is a conference room since all users
            //should see the same roomName.
            command2 = "sp_tb_user_GetOtherUserInRoom @roomID='" + row["roomID"].ToString() + "',@userID='" + this.userName + "'";
            sda2 = new SqlDataAdapter(command2, sqlCon);
            dsReminders2 = new DataTable();
            sda2.Fill(dsReminders2);
            row["roomName"] = dsReminders2.Rows[idx]["userRealName"];
            idx++;
        }
        
        sqlCon.Close();
        return dsReminders;
    }    
}
